<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<html>
	<head>
		<title>店铺管理</title>
		<script type="text/javascript">
		var datatable_content;
		$(function(){
			initTable();
		});
		
		function initTable(){
			datatable_content = $("#contentTable").dataTable({
			   "bServerSide":true,
	           "sAjaxSource":'${ctx}/v2/shopSource/page',
	           "fnServerData": callback,
	           "bFilter": false,
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true,
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	             "aoColumns":[
	             	 {"mData": "shopName"},
	             	 {"mData": "shopCode"},
	             	 {"mData": "customers","render":function(data,type,full){
	             		 return full ? full.customerCode : '';
	             	 }},
	             	 {"mData": null},
	             	 {"mData": "status"},
	             	 {"mData": "id"},
	             ],
	             "aoColumnDefs":[
	                {"aTargets": [3],
		              "mRender": function (data, display, row) {
			        	 return row.ordenoSource ? row.ordenoSource.ordenoSourceName : "";
			           }
		            },
	             	{"aTargets": [4],
		              "mRender": function (data, display, row) {
			        	 return data == "normal" ? "正常" : data == "delete" ? "已删除" : "";
			           }
		            },
	             	{"aTargets": [5],
		               "mRender": function (data, display, row) {
			        	return "<a href='${ctx}/v2/shopSource/update/"+data+"' class='btn btn-primary btn-sm'>修改</a>"+
			        	       "<a href='${ctx}/v2/shopSource/delete/"+data+"' class='btn btn-danger btn-sm'>删除</a>";
			           }
		            },
	             ],
			});
		}
		
		function callback( sSource, aoData, fnCallback ) {
		 aoData.push( { "name": "search_LIKE_shopName", "value": $("#search_LIKE_shopName").val()});  
			 //查询参数
		   $.ajax({ 
		       "type": "post",
		       "contentType": "application/json", 
		       "url": sSource,    
		       "dataType": "json",   
		       "data": JSON.stringify(aoData),
		       "success": fnCallback  
		   });    
		}
		
		function query(){
			datatable_content.fnDestroy();
			initTable();
		}
	function ajaxGetJdMessage(item) {
		$.ajax({
					type : 'post',
					url : '${ctx}/jd/ajaxGetJdMessage',
					data : 'shopCode=' + item,
					dataType : 'json',
					success : function(data) {
						if (data.status == "1") {
							var tempString = "http://auth.sandbox.360buy.com/oauth/authorize?response_type=code&client_id="
									+ data.appKey
									+ "&redirect_uri="
									+ data.backServerUrl + "&state=1234";
							// location.href=tempString;
							window.open(tempString, "", "", "");
						} else {
							alert(data.content);
						}

					},
					error : function() {
						alert("获取信息错误");
					}
				});
	}
</script>
	</head>

	<body>
	<section class="content">
		<c:if test="${not empty message}">
			<div id="message" class="alert alert-success">
				<button data-dismiss="alert" class="close" type="button">
					×
				</button>
				${message}
			</div>
		</c:if>
		<div class="row">
			<div class="col-md-12">
			<div class="box box-solid box-primary">
			<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
				<form class="form-search" action="#">
					<label>
						名称：
					</label>
					<input type="text" name="search_LIKE_showName" class="input-medium" id="search_LIKE_shopName"
						value="${param.search_LIKE_shopName}" onkeydown='if(event.keyCode==13) {query(); return false;}'>
					<button type="button" class="btn btn-info" onclick="query()">
						搜索
					</button>
					<a class="btn btn-info" href="${ctx}/v2/shopSource/create">新增店铺</a>
				</form>
			</div>
			</div>
			</div>
		</div>
		<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
		<table id="contentTable"
			class="table table-striped table-bordered table-condensed">
			<thead>
				<tr>
					<th>
						店铺名称
					</th>
					<th>
						店铺编码
					</th>
					<th>
						商家
					</th>
					<th>
						数据来源平台
					</th>
					<th>
						状态
					</th>
					<th>
						管理
					</th>
				</tr>
			</thead>
			<tbody>
			</tbody>
		</table>
		</div>
		</div>
		</div>
		</div>
		</section>
	</body>
</html>
